import type {Directive, DirectiveBinding} from 'vue'

/**
 * 实现自定义指令v-focus
 */
export const vFocus: Directive<HTMLElement, boolean> = {
  // 当被绑定的元素挂载到DOM中时
  mounted(el: HTMLElement, binding: DirectiveBinding<boolean>) {
    el.focus()
  },
  // 当组件更新时
  updated(el: HTMLElement, binding: DirectiveBinding<boolean>) {
    el.focus()
  }
}
